using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input.Touch;

namespace PiratesOfBermuda
{
    static class MyGameHelper
    {
        /// <summary>
        /// Ham giup chuyen toa do tho thanh toa do trong game
        /// </summary>
        /// <param name="gs">Thong tin ve vi tri ma nguoi choi da nhan len man hinh</param>
        /// <returns>Vi tri tren ban do
        /// Neu nam ngoai pham vi ban do thi tra ve (-1,-1)
        /// </returns>
        public static Point ConvertToMapCoordinate(GestureSample gs)
        {
            int touchX = (int)gs.Position.X;
            int touchY = (int)gs.Position.Y;
            if (touchX < Constants.InitialPositionX
                || touchX > Constants.InitialPositionX + Constants.MapX * Constants.MapPieceWidth
                || touchY < Constants.InitialPositionY
                || touchY > Constants.InitialPositionY + Constants.MapY * Constants.MapPieceHeight)
            {
                return new Point(-1, -1);
            }
            else
            {
                int X = (touchX - Constants.InitialPositionX) / Constants.MapPieceWidth;
                int Y = (touchY - Constants.InitialPositionY) / Constants.MapPieceHeight;
                return new Point(X, Y);
            }
        }
    }
}
